package com.moon.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moon.common.model.entity.InterfaceInfo;
import com.moon.common.model.entity.User;
import com.moon.common.service.InnerInterfaceInfoService;
import com.moon.project.common.ErrorCode;
import com.moon.project.exception.BusinessException;
import com.moon.project.mapper.InterfaceInfoMapper;
import com.moon.project.service.InterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * 作者博客：<a href="https://blog.csdn.net/weixin_65935065">https://blog.csdn.net/weixin_65935065</a>
 * @author 苦行修士
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;


    /**
     * 从数据库中查询模拟接口是否存在（请求路径、请求方法、请求参数）返回接口信息，为空表示不存在
     *
     * @param url
     * @param method
     * @return
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {
        if (StringUtils.isAnyBlank(url, method)) {
            throw new BusinessException(ErrorCode.FORBIDDEN_ERROR,"用户密钥为空");
        }
        QueryWrapper<InterfaceInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("method",method).eq("url",url);
        return interfaceInfoMapper.selectOne(queryWrapper);
    }
}
